unit variacionSueldos;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Provider, SqlExpr, DB, DBClient, DBLocal, DBLocalS, Grids,
  DBGrids, RXDBCtrl, StdCtrls, Mask, ToolEdit, Buttons, DateUtils, Menus;

type
  TfrmVariacionSueldos = class(TForm)
    lblFechaIni: TLabel;
    edtFechaIni: TDateEdit;
    lblFechaFin: TLabel;
    edtFechaFin: TDateEdit;
    grdVarSueldos: TRxDBGrid;
    cds: TSQLClientDataSet;
    s: TDataSource;
    cdsAPENOM: TStringField;
    cdsMAXIMO: TFloatField;
    cdsMINIMO: TFloatField;
    cdsVARIACION: TFloatField;
    BitBtn1: TBitBtn;
    PopupMenu1: TPopupMenu;
    Verdetalle1: TMenuItem;
    cdsID_OPERARIO: TSmallintField;
    Label2: TLabel;
    edtFiltroMaterial: TEdit;
    procedure cdsBeforeOpen(DataSet: TDataSet);
    procedure grdVarSueldosTitleClick(Column: TColumn);
    procedure BitBtn1Click(Sender: TObject);
    procedure Verdetalle1Click(Sender: TObject);
    procedure edtFiltroMaterialChange(Sender: TObject);
    procedure edtFechaIniChange(Sender: TObject);
    procedure grdVarSueldosDrawColumnCell(Sender: TObject;
      const Rect: TRect; DataCol: Integer; Column: TColumn;
      State: TGridDrawState);
  private
    { Private declarations }
  public
    constructor CreateNuevo(AOwner: TComponent);
  end;

var
  frmVariacionSueldos: TfrmVariacionSueldos;

implementation

uses detalleSueldos;

{$R *.dfm}

{ TfrmVariacionSueldos }

constructor TfrmVariacionSueldos.CreateNuevo(AOwner: TComponent);
begin
  inherited Create(Aowner);
  self.edtFechaIni.Date := IncYear(now, -1);
  self.edtFechaFin.Date := now;
  self.ShowModal;
end;

procedure TfrmVariacionSueldos.cdsBeforeOpen(DataSet: TDataSet);
begin
  self.cds.Params[0].AsString := FormatDateTime('mm/dd/yy', StrToDate(self.edtFechaIni.EditText));
  self.cds.Params[1].AsString := FormatDateTime('mm/dd/yy', incDay(StrToDate(self.edtFechaFin.EditText)));
end;

procedure TfrmVariacionSueldos.grdVarSueldosTitleClick(Column: TColumn);
begin
  self.cds.IndexFieldNames := Column.FieldName;
end;

procedure TfrmVariacionSueldos.BitBtn1Click(Sender: TObject);
begin
  self.cds.Close;
  self.cds.Open;
end;

procedure TfrmVariacionSueldos.Verdetalle1Click(Sender: TObject);
begin
  TfrmDetalleSueldos.CreateNuevo(self, FormatDateTime('mm/dd/yy', StrToDate(self.edtFechaIni.EditText)),
  FormatDateTime('mm/dd/yy', incDay(StrToDate(self.edtFechaFin.EditText))),
  self.cdsAPENOM.AsString, self.cdsID_OPERARIO.asInteger);
end;

procedure TfrmVariacionSueldos.edtFiltroMaterialChange(Sender: TObject);
begin
  self.cds.Filtered := False;
  self.cds.Filter := 'APENOM like ''%'+self.edtFiltroMaterial.Text+'%''';
  self.cds.Filtered := True;
end;

procedure TfrmVariacionSueldos.edtFechaIniChange(Sender: TObject);
begin
  try
    self.BitBtn1Click(Sender);
  except
  end;
end;

procedure TfrmVariacionSueldos.grdVarSueldosDrawColumnCell(Sender: TObject;
  const Rect: TRect; DataCol: Integer; Column: TColumn;
  State: TGridDrawState);
var
  valor: string;
  i: integer;
begin
  if (Column.FieldName = 'VARIACION') then
    if not Column.Field.IsNull then
    begin
      valor := FloatToStrF(StrToFloat(Column.Field.AsString), ffNumber,15, 2);
      if (Column.Field.Value < 0) then
        (Sender as TDBGrid).Canvas.Font.Color := clRed
      else
        (Sender as TDBGrid).Canvas.Font.Color := clBlack;
      i := Rect.Right-(Sender as TDBGrid).Canvas.TextWidth(valor+' ');
      (Sender as TDBGrid).Canvas.TextRect(Rect, i, Rect.Top + 2, valor);
    end;
end;

end.
